<template>
  <div id="orders">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <el-row>
        <el-col :span="6">
          <el-input
            placeholder="请输入搜索内容"
            v-model="queryInfo.query"
            clearable
            @clear="getOrdersList()"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getOrdersList()"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column label="#" type="index" width="50" />
        <el-table-column prop="order_number" label="订单编号" />
        <el-table-column prop="order_price" label="订单价格" />
        <el-table-column label="是否付款">
          <template v-slot="scope">
            <el-tag effect="dark" size="mini" v-if="scope.row.order_pay == 1"
              >已付款</el-tag
            >
            <el-tag effect="dark" type="danger" size="mini" v-else
              >未付款</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column label="是否发货">
          <template v-slot="scope">
            <span v-if="scope.row.is_send == '是'">是</span>
            <span v-else>否</span>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template v-slot="scope">
            {{ scope.row.create_time | dataFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-tooltip content="修改订单地址" placement="top">
              <el-button
                type="primary"
                icon="el-icon-edit"
                size="mini"
                @click="editDialogVisible = true"
              />
            </el-tooltip>
            <el-tooltip content="物流信息" placement="top">
              <el-button
                type="success"
                icon="el-icon-location-outline"
                size="mini"
                @click="play"
              />
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[2, 5, 10, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      >
      </el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="editDialogVisible"
      width="40%"
      @close="editDialogVisibleClose"
    >
      <el-form
        :model="editRuleForm"
        :rules="editRules"
        ref="editRuleForm"
        label-width="100px"
      >
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader :options="cityOptions" v-model="editRuleForm.address1">
          </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="editRuleForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editDialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>

    <!-- 物流对话框 -->
    <el-dialog title="物流进度" :visible.sync="playDialogVisible" width="40%">
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in playInfo"
          :key="index"
          :timestamp="activity.time"
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import "@/assets/css/orders/orders.scss";
import cityOptions from "../../public/city_data2017_element.js";

export default {
  data() {
    return {
      tableData: [],
      total: 0,
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 10,
      },
      editDialogVisible: false,
      editRuleForm: {
        address1: [],
        address2: "",
      },
      editRules: {
        address1: [
          { required: true, message: "请选择省市区/县", trigger: "blur" },
        ],
        address2: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
      },
      cityOptions,
      playDialogVisible: false,
      playInfo: [],
    };
  },
  created() {
    this.getOrdersList();
  },
  methods: {
    async getOrdersList() {
      const { data: res } = await this.axios.get("/orders", {
        params: this.queryInfo,
      });
      if (res.meta.status == 200) {
        this.tableData = res.data.goods;
        // console.log(this.tableData);
        this.total = res.data.total;
      } else {
        this.$message.error(res.meta.msg);
      }
    },
    handleSizeChange(val) {
      this.queryInfo.pagesize = val;
      this.getOrdersList();
    },
    handleCurrentChange(val) {
      this.queryInfo.pagenum = val;
      this.getOrdersList();
    },
    editDialogVisibleClose() {
      this.$refs.editRuleForm.resetFields();
    },
    async play() {
      this.playDialogVisible = true;
      const { data: res } = await this.axios.get("/kuaidi/804909574412544580");
      // console.log(res)
      if (res.meta.status == 200) {
        this.playInfo = res.data;
      } else {
        this.$message.error(res.meta.msg);
      }
    },
  },
};
</script>

<style scoped></style>
